package cn.wxq.daily.empdailymgforserve.controller;

import cn.wxq.daily.empdailymgforserve.domain.AbilityPaper;
import cn.wxq.daily.empdailymgforserve.domain.AbilitySingle;
import cn.wxq.daily.empdailymgforserve.model.Result;
import cn.wxq.daily.empdailymgforserve.model.StatusCode;
import cn.wxq.daily.empdailymgforserve.service.AbilityPaperService;
import cn.wxq.daily.empdailymgforserve.service.AbilitySingleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@CrossOrigin //跨越处理
@RestController
@RequestMapping("/abilityPaper")
@Api(value = "AbilityPaperController|试卷管理")
public class AbilityPaperController {
    @Autowired
    private AbilityPaperService abilityPaperService;

    @Autowired
    private AbilitySingleService abilitySingleService;

    @RequestMapping(value = "/addPaper", method = RequestMethod.POST)
    @ApiOperation(value = "新增试卷")
    public Result addPaper(AbilityPaper abilityPaper ) {
        int row = abilityPaperService.addPaper(abilityPaper);
        if (row >0) {
            return new Result(true, StatusCode.OK, "新增成功");
        } else {
            return new Result(false, StatusCode.ERROR, "新增异常");
        }
    }
    @RequestMapping(value = "/findPaperByPage", method = RequestMethod.POST)
    @ApiOperation(value = "条件查询试卷")
    public Result findPaperByPage(AbilityPaper abilityPaper ) {
        List<AbilityPaper> paperByPage = abilityPaperService.findPaperByPage(abilityPaper);
        if (paperByPage != null) {
            return new Result(true, StatusCode.OK, "成功",paperByPage);
        } else {
            return new Result(false, StatusCode.ERROR, "异常");
        }
    }

    @RequestMapping(value = "/updatePaper", method = RequestMethod.POST)
    @ApiOperation(value = "修改试卷")
    public Result updatePaper(AbilityPaper abilityPaper ) {
        int row = abilityPaperService.update(abilityPaper);
        if (row >0) {
            return new Result(true, StatusCode.OK, "修改成功");
        } else {
            return new Result(false, StatusCode.ERROR, "数据异常");
        }
    }

    @RequestMapping(value = "/deletePaperById", method = RequestMethod.POST)
    @ApiOperation(value = "删除试卷")
    public Result deletePaperById(Integer alityPaperId ) {
        int row = abilityPaperService.delete(alityPaperId);
        if (row >0) {
            return new Result(true, StatusCode.OK, "删除成功");
        } else {
            return new Result(false, StatusCode.ERROR, "删除异常");
        }
    }

    /**
     * 往试卷中新增试题
     * @param abilitySingle
     * @return
     */
    @RequestMapping(value = "/addQuestion", method = RequestMethod.POST)
    @ApiOperation(value = "往试卷中新增试题")
    public Result addQuestion(AbilitySingle abilitySingle ) {
        //前端获取到试卷id,一并传过来

        int row = abilitySingleService.addQuestion(abilitySingle);
        if (row >0) {
            return new Result(true, StatusCode.OK, "新增成功");
        } else {
            return new Result(false, StatusCode.ERROR, "新增异常");
        }
    }
}
